
	var house_img = document.getElementById("house_img");
	var code_img = document.getElementById("code");

	$.fn.imgupload=function(){
		if(typeof FileReader === 'undefined') {
			result.innerHTML = "抱歉，你的浏览器不支持 FileReader";
		} else {
			if($(this).length!=0) {
				$.each($(this), function(i,v) {
					v.addEventListener('change', readFiledes, false);
				});
			}

		}
	}

	function readFiledes() {
		var new_img, img, del;
		var formData = new FormData();
		var $that = $(this),ajaxIndex=0;;
       
		for(var i = 0; i < this.files.length; i++) {
            console.log(this.files[i]);
         if(this.files[i].size<=(10*1024*1024)){
			var reader = new FileReader();
			reader.readAsDataURL(this.files[i]);
			formData.append("file", this.files[i]);

			reader.onload = function(e) {
				//				new_img = document.createElement('div');
				new_img = $("<div style='position:relative;'>");
				new_img.attr('class', 'new_img');

				img =  $("<img>");
				img.attr("src", this.result);

//				del = document.createElement('i');
//				del.setAttribute('class', 'iconfont icon-shanchu1')
                
                del=$('<svg class="icon" aria-hidden="true" style="color:#4e8cef;font-size: 24px; position:absolute;top:-0.1rem;right:-0.1rem;"><use xlink:href="#icon-shanchu"></use></svg>');
                    
				del[0].onclick = function() {
					$(this).css("display", "none");
					$(this).parent().remove();
                    var aw=[];
                    $that.parent().parent().find(".new_img img").each(function(i,v){
                       if($(v).attr("data-url")!=""&&!!$(v).attr("data-url")){
							 aw.push($(v).attr("data-url"));
                            }
						});
						var strs=aw.join("|");
						$that.parent().find(".i_id").val(strs);
				}

				new_img.append(del);
				new_img.append(img);
				console.log($('.code_wrap').children('div'));
				if($that.parent().parent().attr('class').indexOf("house_wrap") > 0) {
					console.log();
					if($('.house_wrap').find('div.new_img').length >= 9) {
						alert('图片个数个数已达上限！');
						return false;
					}

				} else if($that.parent().parent().attr('class').indexOf("code_wrap") > 0){
					if($('.code_wrap').find('div.new_img').length >= 1) {
						alert('图片个数个数已达上限！');
						return false;
					}
				}else{
					if($('.com_wrap').find('div.new_img').length >= 1) {
						alert('图片个数个数已达上限！');
						return false;
					}
				}
				$that.parent().before(new_img);
                
				$.ajax({
					type: "POST",
					url: 'http://www.caizhanzhushou.com/index.php?g=Wechat&m=webzhuan&a=ajax',
					data: formData,
					processData: false,
					contentType: false,
					success: function(res) {
						var aw=[];
						var data=res.slice(0,res.length-1);
                        $that.parent().parent().find('.new_img img').eq(ajaxIndex).attr("data-url",data);
//						img_des_arr.push(res.data.url);
						$that.parent().parent().find(".new_img img").each(function(i,v){
                            if($(v).attr("data-url")!=""&&!!$(v).attr("data-url")){
							 aw.push($(v).attr("data-url"));
                            }
						});
						var strs=aw.join("|");
						$that.parent().find(".i_id").val(strs);
                        ajaxIndex++;
					}
				});
				　　　　　　　　　　　　　　
			}
        }else{
            alert("请选择小于10m的图片！")
        }
		}
        
	}

//验证码倒计时插件
 var toggleAlert=function(msg){
    $(".alertMsg").addClass("on").find("span").html(msg);
    setTimeout(function(){
        $(".alertMsg").removeClass("on");
    },2000);
};
var fsMsg=function(){};
fsMsg.prototype={
	init:function(json){
		this.obj=null;
		this.num=json.num||60;
		this.tin=null;
		this.bind(json);
        this.json=json;
        return this;
	},
	bind:function(json){
		var self=this;
		$(document).on("click touchstart",json.class,function(){
			//写接口
			self.obj=$(this)[0];
			if(!$(this).hasClass("on")&&self.bindInput(json)){
				clearInterval(self.tin);
                var tel=self.input.val();
                 $.get('http://www.caizhanzhushou.com/index.php?g=Wechat&m=Common&a=send&num='+tel,function(data){
                         self.tate=data;
//                        this.input.data
                     self.bindSubmit();
                 });
				self.tin=setInterval(function(){
					self.autoplay(json);
				},1000);
				$(this).addClass("on");
			}
		});
	},
	bindInput:function(json){
        var self=this;
		this.input=$(self.obj).parents("form").find(json.input);
		var reg = /^1[3578]\d{9}$/;
		if(this.input.val()!=""){
			if(reg.test(this.input.val())){
				return true;
			}else{
				toggleAlert("手机号错误");
				return false;
			}
		}else{
			toggleAlert("验证码不能为空");
			return false;
		}
		return false;
	},
    bindSubmit:function(){
        var self=this,json=this.json;
        $(self.obj).parents("form").off("submit");
        $(self.obj).parents("form").on("submit",function(){
            self.code=$(self.obj).parents("form").find(json.code).val();
            console.log(self.tate)
            if(self.code!=self.tate){
                toggleAlert("验证码错误");
                return false;
            }
        });
    },
	autoplay:function(json){
        var self=this;
		this.num--;
		if(this.num>=0){
			this.obj.style.color="red";
			this.obj.innerHTML=this.num+"s后重发";
			
		}else{
			this.obj.style.color="red";
			this.obj.innerHTML="重新发送验证码";
			$(this.obj).removeClass("on");
			this.obj.disabled=false;
			clearInterval(self.tin);
			this.num=json.num||60;
		}
	}
}
var fsTime=new fsMsg();
